public class Solution67 {
    public String addBinary(String a, String b) {
        int len=Math.max(a.length(),b.length());
        int[] i1=new int[len];
        for (int i=0;i<a.length();i++){
            i1[i]=a.charAt(a.length()-i-1)-'0';
        }
        int[] i2=new int[len];
        for (int i=0;i<b.length();i++){
            i2[i]=b.charAt(b.length()-i-1)-'0';
        }
        int[] i3=new int[len+1];
        for (int i=0;i<len;i++){
            i3[i]+=i1[i]+i2[i];
            if (i3[i]>=2){
                i3[i+1]++;
                i3[i]-=2;
            }
        }
        int start=i3[len]==0?len-1:len;
        StringBuilder stringBuilder=new StringBuilder();
        for (int i=start;i>=0;i--){
            stringBuilder.append(i3[i]);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution67().addBinary("11","1"));
    }
}
